define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'instrument/index',
                    add_url: 'instrument/add',
                    edit_url: 'instrument/edit',
                    del_url: 'instrument/del',
                    import_url:'instrument/import',
                    multi_url: 'instrument/multi',
                    table: 'instrument',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                columns: [
                    [
                        {checkbox: true},
                        // {field: 'id', title: __('Id')},
                        // {field: 'admin_id', title: __('Admin_id')},
                        {field: 'title', title: __('Title')},
                        {field: 'titleen', title: __('Titleen')},
                        {field: 'type', title: __('Type')},
                        {field: 'iconimage', title: __('Iconimage'), formatter: Table.api.formatter.image},
                        {field: 'fileimage', title: __('Fileimage'), formatter: Table.api.formatter.image},
                        {field: 'suffix1', title: __('Suffix1')},
                        {field: 'suffix2', title: __('Suffix2')},
                        {field: 'suffix3', title: __('Suffix3')},
                        {field: 'measurecontent', title: __('Measurecontent')},
                        {field: 'unit', title: __('Unit')},
                        {field: 'storagespace', title: __('Storagespace')},
                        {field: 'maxfilenum', title: __('Maxfilenum')},
                        // {field: 'field1', title: __('Field1')},
                        // {field: 'field2', title: __('Field2')},
                        // {field: 'field3', title: __('Field3')},
                        // {field: 'field4', title: __('Field4')},
                        // {field: 'field5', title: __('Field5')},
                        // {field: 'refreshtime', title: __('Refreshtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'weigh', title: __('Weigh')},
                        {field: 'state', title: __('State'), visible:false, searchList: {"state 0":__('State 0'),"state 1":__('State 1'),"state 2":__('State 2')}},
                        {field: 'state_text', title: __('State'), operate:false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});